package com.ggdog.blog.Controller;

import com.ggdog.blog.POJO.Result;
import com.ggdog.blog.POJO.Project;
import com.ggdog.blog.Services.ProjectServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectServices projectServices;

    @RequestMapping("/addProject")
    public int addProject(String projectName, String projectDescription, String projectUrl, String projectImageUrl, String projectGitUrl, String projectType) {
        return projectServices.addProject(projectName, projectDescription, projectUrl, projectImageUrl, projectGitUrl, projectType);
    }
    @RequestMapping("/getAllProject")
    public Result<List<Project>> getAllProject() {
        List<Project> projects = projectServices.getAllProject();
        if (projects==null){
            System.out.println("获取失败");
            return Result.error("获取失败");
        }
        Result<List<Project>> result = Result.success(projects);
        System.out.println("所有项目："+projects);
        return result;
    }
}
